﻿using MrPP.UX;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MrPP.SerriedCabinet
{
    public class BoxAction : MonoBehaviour
    {
        [SerializeField]
        private BoxBridging _bridging;

        private void onAction(int type) {
            Debug.LogError("type:" + type);
            if (type == 1)
            {
                _bridging.doVentilate();
               // BoxOperation.Instance.ventilate();
                //通风
            }
            else if (type == 3)
            {

                _bridging.doClose();
                //BoxOperation.Instance.close();
                //关闭
            }
            else {

                if (CabinetGroup.Instance.fix != this.target_)
                {
                    if (this.target_ < CabinetGroup.Instance.fix)
                    {
                        if (type == 0)
                        {

                            _bridging.doOpen(target_);
                            //BoxOperation.Instance.open(target_);
                        }
                        else if (type == 2)
                        {

                            _bridging.doClose();
                            //BoxOperation.Instance.close(target_);
                        }
                    }
                    else
                    {

                        if (type == 0)
                        {
                            _bridging.doClose();
                           // BoxOperation.Instance.open(target_);
                        }
                        else if (type == 2)
                        {

                            _bridging.doOpen(target_);
                           // _bridging.doClose();
                            //BoxOperation.Instance.close(target_);
                        }
                    }

                }
            
            }
         
        }
        private int target_ = -1;
        public void onPress(IntId id) {

            if (BoxRoot.Instance.inside(Camera.main.transform.position)) {
                return;
            }
            if (HandMenu.IsInitialized) {
                target_ = id.id;
                HandMenu.Instance.show(4, this.onAction);
            }
        }

        public void onRelease() {
            if (HandMenu.IsInitialized)
            {
                HandMenu.Instance.hidden();
                target_ = -1;
            }
        }
    }
}